package top.hkyzf.study.leetcode.array;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 朱峰
 * @date 2022-2-14 9:58
 */
public class 杨辉三角_118 {
    List<List<Integer>> result = new ArrayList<>();

    public List<List<Integer>> generate(int numRows) {
        for (int i = 0; i < numRows; i++) {
            List<Integer> list = new ArrayList<>();
            dfs(list, i);
            result.add(list);
        }
        return result;
    }

    private void dfs(List<Integer> list, int i) {
        if (i == 0) {
            list.add(1);
            return;
        }
        for (int j = 0; j <= i; j++) {
            if (j == 0 || j == i) {
                list.add(1);
            } else {
                List<Integer> integerList = result.get(i - 1);
                list.add(integerList.get(j-1) + integerList.get(j));
            }
        }
    }

    @Test
    public void testGenerate () {
        int numRows = 5;
        System.out.println(generate(numRows));
    }
}
